package com.woniu.woniuproject.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.woniuproject.entity.Product;
import com.woniu.woniuproject.mapper.ProductMapper;
import com.woniu.woniuproject.mapper.UserMapper;
import com.woniu.woniuproject.vo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Autowired
    UserMapper userMapper;
    public void addProduct(Product product){
    productMapper.insert(product);
    }
    public void updateProduct(Product product){
    productMapper.updateByPrimaryKey(product);
    }

    public void deleteProduct(int proId){
    productMapper.deleteByPrimaryKey(proId);
    }
    public PageInfo<Product> queryProductPage(Page page){
        PageHelper.startPage(page.getNowPage(),page.getMaxPage()); //mybatis的查询拦截
        List<Product> products = productMapper.selectAll();
        PageInfo<Product> Info = new PageInfo<>(products);
        return Info ;
    }

}
